package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mappers.MockMapper;
import com.tanhua.model.domain.Mock;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class MockApiImpl implements MockApi {
    @Autowired
    private MockMapper mockMapper;

    /**
     * 获取试卷列表
     * @return
     */
    @Override
    public List<Mock> findMockList() {
        LambdaQueryWrapper<Mock> wrapper = new LambdaQueryWrapper<>();
        //按难度星级排序
        wrapper.orderByAsc(Mock::getStar);
        List<Mock> mocks = mockMapper.selectList(wrapper);
        return mocks;
    }

    /**
     * 根据id查问卷
     * @param mockId
     * @return
     */
    @Override
    public Mock findById(String mockId) {
        return mockMapper.selectById(mockId);
    }

    /**
     * 解锁问卷
     * @param unLockLevel
     */
    @Override
    public void unLOCK(String unLockLevel) {
        //更新
        Mock mock = new Mock();
        mock.setIsLock(0);
        //更新条件
        LambdaQueryWrapper<Mock> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Mock::getLevel,unLockLevel);
        mockMapper.update(mock,wrapper);
    }
}
